/**
 * 给定01数组，要求相邻1之间至少间隔k个零
 * 
 */
class Solution {
public:
    bool kLengthApart(vector<int>& nums, int k) {
        int n = nums.size();
        int Limit = k;
        k = 0;
        while(k < n and nums[k] == 0) ++k;
        if(k == n) return true;

        while(1){
            assert(nums[k] == 1);
            ++k;
            if(k == n) break;

            int o = 0;
            while(k + o < n and nums[k + o] == 0) ++o;
            if((k += o) == n) break;
            if(o < Limit) return false;
        } 
        return true;
    }
};